package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

@Mapper
public interface SetmealMapper {

    //分页查询
    Page<Setmeal> pageQuerySetmeal(SetmealPageQueryDTO setmealPageQueryDTO);

    //新增套餐
    void addSetmeal(Setmeal setmeal);

    //根据id查询套餐
    @Select("select * from sky_take_out.setmeal where id = #{id}")
    SetmealVO selectSetmealById(Long id);

    //更新启售状态
    @Update("update sky_take_out.setmeal set status=#{status},update_time=NOW(),update_user=#{updateUser} where id=#{id}")
    void updateSetmealStatus(Integer status,Integer id,Long updateUser);

    //更新菜品信息
    void updateSetmeal(Setmeal setmeal);

    //删除菜品信息
    void deleteSetmeal(List<Long> ids);

    //动态条件查询套餐
    List<Setmeal>  list(Setmeal setmeal);

    //根据套餐id查询菜品选项
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);

    //根据条件统计套餐数量
    Integer countByMap(Map map);
}

